<?php

namespace app\index\controller;
use app\common\controller\AuthBase;
use app\common\model\log\ReportUrlRecord;
use think\Validate;

class Reportlog extends AuthBase {
    
    public function _initialize() {
        parent::_initialize();
    }

    /**
     * 添加报表日志
     */
    public function addReportLog(){
        $params = $this->input();
        $rule = [
            "type" => 'require',
            "date"=>'require',
            "url"=>'require'
        ];
        
        $validate = new Validate($rule);
        if(!$validate->check($params)){
            return $this->output([], $validate->getError());
        }
        
        $ReportUrlRecordModel = new ReportUrlRecord();
        $reportUrlRecord = $ReportUrlRecordModel->addRecord($params);
        if($reportUrlRecord === false){
            return $this->output([],'insert error');
        }
        
        return $this->output([]);
    }
    
    
    /**
     * 获取日报表的url数据
     * @return type
     */
    public function getReportLog(){
        
        $params = $this->input();
        $rule = [
            "type" => 'require',
            "start_date" => 'require',
            "end_date" => 'require'
        ];
        
        $validate = new Validate($rule);
        if(!$validate->check($params)){
            return $this->output([], $validate->getError());
        }
        
        $ReportUrlRecordModel = new ReportUrlRecord();
        $reportUrlRecord = $ReportUrlRecordModel->getList($params);
        
        return $this->output($reportUrlRecord);
    }
}